home *** CD-ROM | disk | FTP | other *** search
/ Gigantic Games 2 / Gigantic Games 2.iso / pc / _z_ / zorkmachine / wb.c < prev    next >
C/C++ Source or Header  |  1994-12-23  |  8KB  |  347 lines

  1. #include <workbench/workbench.h>
  2. #include <workbench/startup.h>
  3.  
  4. #include <clib/exec_protos.h>
  5. #include <clib/icon_protos.h>
  6.  
  7. #include <string.h>
  8. #include <stdlib.h>
  9.  
  10. enum    {    FILETYPE_UNKNOWN, FILETYPE_STORY, FILETYPE_BOOKMARK };
  11.  
  12. extern struct WBStartup    *WBenchMsg;
  13. extern struct Library    *IconBase;
  14. extern struct Screen    *Screen;
  15.  
  16. extern char        *story_name,
  17.              print_name[];
  18. extern int         printer_width;
  19.  
  20. USHORT IconData[144] =
  21. {
  22.     0x0000,0x0007,0xF000,0x0000,0x0000,0x0007,0xF000,0x0000,
  23.     0xFFFF,0xFFFF,0xFFFF,0xF800,0x8000,0x0067,0xF000,0x1800,
  24.     0x8000,0x0067,0xF000,0x1800,0x8FFF,0xFC67,0xFFFF,0x1800,
  25.     0x8000,0x0067,0xF000,0x1800,0x8FFF,0xFC67,0xFFFF,0x1800,
  26.     0x8000,0x0067,0xF000,0x1800,0x8FFF,0xFC67,0xF000,0x1800,
  27.     0x8000,0x0067,0xFFFF,0x1800,0x8000,0x0067,0xF000,0x1800,
  28.     0x8FFF,0xFC67,0xFFFF,0x1800,0x8000,0x0060,0x0000,0x1800,
  29.     0x8FFF,0xFC67,0xFFFF,0x1800,0x8000,0x0060,0x0000,0x1800,
  30.     0x8000,0x0060,0x0000,0x1800,0xFFFF,0xFFFF,0xFFFF,0xF800,
  31.  
  32.     0x0000,0x0000,0x0000,0x0000,0x0000,0x0003,0xE000,0x0000,
  33.     0x0000,0x0003,0xE000,0x0000,0x7FFF,0xFF9B,0xEFFF,0xE000,
  34.     0x7FFF,0xFF9B,0xEFFF,0xE000,0x7000,0x039B,0xE000,0xE000,
  35.     0x7FFF,0xFF9B,0xEFFF,0xE000,0x7000,0x039B,0xE000,0xE000,
  36.     0x7FFF,0xFF9B,0xEFFF,0xE000,0x7000,0x039B,0xEFFF,0xE000,
  37.     0x7FFF,0xFF9B,0xE000,0xE000,0x7FFF,0xFF9B,0xEFFF,0xE000,
  38.     0x7000,0x0398,0x0000,0xE000,0x7FFF,0xFF9F,0xFFFF,0xE000,
  39.     0x7000,0x0398,0x0000,0xE000,0x7FFF,0xFF9F,0xFFFF,0xE000,
  40.     0x7FFF,0xFF9F,0xFFFF,0xE000,0x0000,0x0000,0x0000,0x0000
  41. };
  42.  
  43. struct Image IconImage =
  44. {
  45.     0,0,
  46.     53,18,2,
  47.     IconData,
  48.     0x03,0x00,
  49.     (struct Image *)NULL
  50. };
  51.  
  52. struct DiskObject DefaultIcon =
  53. {
  54.     WB_DISKMAGIC,
  55.     WB_DISKVERSION,
  56.  
  57.     (struct Gadget *)NULL,
  58.     323,24,
  59.     53,19,
  60.     0x0005,
  61.     0x0003,
  62.     0x0001,
  63.     (APTR)&IconImage,
  64.     (APTR)NULL,
  65.     (struct IntuiText *)NULL,
  66.     NULL,
  67.     (APTR)NULL,
  68.     NULL,
  69.     (APTR)NULL,
  70.  
  71.     WBPROJECT,
  72.     (char *)NULL,
  73.     NULL,
  74.     NO_ICON_POSITION,
  75.     NO_ICON_POSITION,
  76.     (struct DrawerData *)NULL,
  77.     (char *)NULL,
  78.     10000
  79. };
  80.  
  81. char *Args[13];
  82.  
  83. void
  84. wbtocli(int *argc,char ***argv)
  85. {
  86.     struct DiskObject *Icon;
  87.  
  88.     memset(Args,0,sizeof(Args));
  89.  
  90.     *argc = 1;
  91.     *argv = Args;
  92.  
  93.     Args[0] = WBenchMsg -> sm_ArgList[0] . wa_Name;
  94.  
  95.     if(!IconBase)
  96.     {
  97.         if(!(IconBase = OpenLibrary("icon.library",37)))
  98.             return;
  99.     }
  100.  
  101.     if(WBenchMsg -> sm_NumArgs > 1)
  102.     {
  103.         CurrentDir(WBenchMsg -> sm_ArgList[1] . wa_Lock);
  104.  
  105.         if(Icon = GetDiskObject(WBenchMsg -> sm_ArgList[1] . wa_Name))
  106.         {
  107.             if(Icon -> do_Type == WBPROJECT)
  108.             {
  109.                 UBYTE    *Result;
  110.                 BYTE     Type = FILETYPE_UNKNOWN;
  111.  
  112.                 if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"FILETYPE"))
  113.                 {
  114.                     if(stricmp((char *)Result,"Z3SAVEFILE"))
  115.                     {
  116.                         if(!stricmp((char *)Result,"Z3STORY"))
  117.                         {
  118.                             CurrentDir(WBenchMsg -> sm_ArgList[1] . wa_Lock);
  119.  
  120.                             Args[(*argc)++] = "-s";
  121.  
  122.                             if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  123.                                 strcpy(Args[(*argc)++],(char *)Result);
  124.  
  125.                             Type = FILETYPE_STORY;
  126.                         }
  127.                     }
  128.                     else
  129.                         Type = FILETYPE_BOOKMARK;
  130.                 }
  131.  
  132.                 if(Type != FILETYPE_UNKNOWN)
  133.                 {
  134.                     if(FindToolType((UBYTE **)Icon -> do_ToolTypes,"CUSTOMSCREEN"))
  135.                         Args[(*argc)++] = "-c";
  136.  
  137.                     if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"PROTOCOLFILE"))
  138.                     {
  139.                         Args[(*argc)++] = "-p";
  140.  
  141.                         if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  142.                             strcpy(Args[(*argc)++],(char *)Result);
  143.                     }
  144.  
  145.                     if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"PROTOCOLWIDTH"))
  146.                     {
  147.                         Args[(*argc)++] = "-w";
  148.  
  149.                         if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  150.                             strcpy(Args[(*argc)++],(char *)Result);
  151.                     }
  152.  
  153.                     if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"COLOUR0"))
  154.                     {
  155.                         Args[(*argc)++] = "-k";
  156.  
  157.                         if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  158.                             strcpy(Args[(*argc)++],(char *)Result);
  159.                     }
  160.  
  161.                     if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"COLOUR1"))
  162.                     {
  163.                         Args[(*argc)++] = "-l";
  164.  
  165.                         if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  166.                             strcpy(Args[(*argc)++],(char *)Result);
  167.                     }
  168.  
  169.                     if(Type == FILETYPE_BOOKMARK)
  170.                     {
  171.                         if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"STORYFILE"))
  172.                         {
  173.                             Args[(*argc)++] = "-s";
  174.  
  175.                             if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  176.                                 strcpy(Args[(*argc)++],(char *)Result);
  177.                         }
  178.  
  179.                         Args[(*argc)++] = "-r";
  180.  
  181.                         if(Args[*argc] = malloc(strlen(WBenchMsg -> sm_ArgList[1] . wa_Name) + 1))
  182.                             strcpy(Args[*argc],WBenchMsg -> sm_ArgList[1] . wa_Name);
  183.                         else
  184.                             (*argc)--;
  185.                     }
  186.                 }
  187.             }
  188.  
  189.             FreeDiskObject(Icon);
  190.         }
  191.     }
  192.     else
  193.     {
  194.         if(Icon = GetDiskObject(WBenchMsg -> sm_ArgList[0] . wa_Name))
  195.         {
  196.             if(Icon -> do_Type == WBTOOL)
  197.             {
  198.                 UBYTE *Result;
  199.  
  200.                 if(FindToolType((UBYTE **)Icon -> do_ToolTypes,"CUSTOMSCREEN"))
  201.                     Args[(*argc)++] = "-c";
  202.  
  203.                 if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"PROTOCOLFILE"))
  204.                 {
  205.                     Args[(*argc)++] = "-p";
  206.  
  207.                     if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  208.                         strcpy(Args[(*argc)++],(char *)Result);
  209.                 }
  210.  
  211.                 if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"PROTOCOLWIDTH"))
  212.                 {
  213.                     Args[(*argc)++] = "-w";
  214.  
  215.                     if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  216.                         strcpy(Args[(*argc)++],(char *)Result);
  217.                 }
  218.  
  219.                 if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"COLOUR0"))
  220.                 {
  221.                     Args[(*argc)++] = "-k";
  222.  
  223.                     if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  224.                         strcpy(Args[(*argc)++],(char *)Result);
  225.                 }
  226.  
  227.                 if(Result = FindToolType((UBYTE **)Icon -> do_ToolTypes,"COLOUR1"))
  228.                 {
  229.                     Args[(*argc)++] = "-l";
  230.  
  231.                     if(Args[*argc] = malloc(strlen((char *)Result) + 1))
  232.                         strcpy(Args[(*argc)++],(char *)Result);
  233.                 }
  234.             }
  235.  
  236.             FreeDiskObject(Icon);
  237.         }
  238.     }
  239. }
  240.  
  241. void
  242. saveicon(char *File)
  243. {
  244.     SetProtection(File,FIBF_EXECUTE);
  245.  
  246.     if(WBenchMsg)
  247.     {
  248.         STATIC UBYTE *Types[8] =
  249.         {
  250.             "FILETYPE=Z3SAVEFILE",
  251.             NULL,
  252.             NULL,
  253.             NULL,
  254.             NULL,
  255.             NULL,
  256.             NULL,
  257.             NULL
  258.         };
  259.  
  260.         STATIC UBYTE Buffer[512],NameBuffer[256],PrinterBuffer[256],WidthBuffer[30],Colour0Buffer[30],Colour1Buffer[30];
  261.  
  262.         extern BYTE CustomScreen;
  263.  
  264.         struct DiskObject *Icon;
  265.  
  266.         UBYTE *Tool,Count = 1;
  267.  
  268.         if(NameFromLock(WBenchMsg -> sm_ArgList[0] . wa_Lock,NameBuffer,256))
  269.         {
  270.             if(AddPart(NameBuffer,WBenchMsg -> sm_ArgList[0] . wa_Name,256))
  271.                 Tool = NameBuffer;
  272.             else
  273.                 Tool = WBenchMsg -> sm_ArgList[0] . wa_Name;
  274.         }
  275.         else
  276.             Tool = WBenchMsg -> sm_ArgList[0] . wa_Name;
  277.  
  278.         Icon = GetDiskObject("Icon.Data");
  279.  
  280.         Types[Count++] = Buffer;
  281.  
  282.         if((char *)FilePart(story_name) == story_name)
  283.         {
  284.             strcpy(Buffer,"STORYFILE=");
  285.  
  286.             if(!GetCurrentDirName(&Buffer[10],500))
  287.                 strcpy(&Buffer[10],story_name);
  288.             else
  289.             {
  290.                 if(!AddPart(&Buffer[10],story_name,500))
  291.                     strcpy(&Buffer[10],story_name);
  292.             }
  293.         }
  294.         else
  295.             sprintf(Buffer,"STORYFILE=%s",story_name);
  296.  
  297.         Types[Count++] = PrinterBuffer;
  298.  
  299.         sprintf(PrinterBuffer,"PROTOCOLFILE=%s",print_name);
  300.  
  301.         Types[Count++] = WidthBuffer;
  302.  
  303.         sprintf(WidthBuffer,"PROTOCOLWIDTH=%ld",printer_width);
  304.  
  305.         if(CustomScreen)
  306.         {
  307.             Types[Count++] = "CUSTOMSCREEN";
  308.  
  309.             if(Screen)
  310.             {
  311.                 sprintf(Colour0Buffer,"COLOUR0=%03lx",GetRGB4(Screen -> ViewPort . ColorMap,0));
  312.  
  313.                 Types[Count++] = Colour0Buffer;
  314.  
  315.                 sprintf(Colour1Buffer,"COLOUR1=%03lx",GetRGB4(Screen -> ViewPort . ColorMap,1));
  316.  
  317.                 Types[Count++] = Colour1Buffer;
  318.             }
  319.         }
  320.  
  321.         Types[Count] = NULL;
  322.  
  323.         if(Icon)
  324.         {
  325.             Icon -> do_DefaultTool    = Tool;
  326.             Icon -> do_ToolTypes    = (char **)Types;
  327.             Icon -> do_CurrentX    = NO_ICON_POSITION;
  328.             Icon -> do_CurrentY    = NO_ICON_POSITION;
  329.  
  330.             if(!PutDiskObject(File,Icon))
  331.                 ConPutS("*** Could not create icon file ***");
  332.  
  333.             FreeDiskObject(Icon);
  334.         }
  335.         else
  336.         {
  337.             DefaultIcon . do_DefaultTool    = Tool;
  338.             DefaultIcon . do_ToolTypes    = (char **)Types;
  339.  
  340.             if(!PutDiskObject(File,&DefaultIcon))
  341.                 ConPutS("*** Could not create icon file ***");
  342.         }
  343.     }
  344.     else
  345.         ConPutS("[No icon]\n");
  346. }
  347.